﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UniMana.Data
{
    public class System_Group_RuleData
    {
        public static IQueryable GetByGroup(int _intGroupKey)
        {
            DBMain data = new DBMain();
            var iQuery =  data.m_DCReadOnly.System_Group_Rules.Where(p=>p.System_GroupKey ==_intGroupKey);
            return iQuery;
        }
        public static IQueryable GetRuleForRemove(int _intGroupKey, Guid system_UserKey)
        {
            DBMain data = new DBMain();

            var iQuery = from p in data.m_DCReadOnly.System_Group_Rules
                          where p.System_GroupKey == _intGroupKey
                          && !(from m1 in data.m_DCReadOnly.System_Group_Rules
                               from m2 in data.m_DCReadOnly.System_User_Groups
                               where m1.System_GroupKey == m2.System_GroupKey
                               && m2.System_UserKey == system_UserKey
                               && m2.System_GroupKey != _intGroupKey
                               select m1.System_RuleKey).Contains(p.System_RuleKey)
                          select p;
            return iQuery;
           
        }
    }
}
